package team.bluepen.order.web.servlet.user;

import team.bluepen.order.constant.Constant;
import team.bluepen.order.data.entity.User;
import team.bluepen.order.web.servlet.BaseServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author RollW
 */
@WebServlet(name = "UserCurrentServlet", urlPatterns = "/api/user/current")
public class UserCurrentServlet extends BaseServlet {
    @Override
    protected void post(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        User user = (User) session.getAttribute(Constant.SESSION_USER);
        setJsonHeader(resp);
        if (user == null) {
            resp.sendError(404);
        }
        writeJson(resp, user);
    }
}
